//
//  FileManagerTest.m
//  MacTestProject
//
//  Created by LiuLichen on 2022/4/12.
//

#import "FileManagerTest.h"

@implementation FileManagerTest

- (id) init {
    self = [super init];

    [self testOperation];

    return self;
}

- (void) testOperation {
    {
        NSFileManager* fileManager = [NSFileManager defaultManager];
        NSString* path = [fileManager currentDirectoryPath];
        NSLog(@"current dir path is %@", path);
        NSString* dirName = @"testDir";
        if ([fileManager createDirectoryAtPath: dirName withIntermediateDirectories: YES attributes: nil error: nil]) {
            NSLog(@"a new folder was created");
        }
        path = [path stringByAppendingPathComponent: dirName];
        NSString* filePath = [path stringByAppendingPathComponent: @"testFile"];
        NSString* str = @"Welcome to the new world!";
        NSData* data = [str dataUsingEncoding: NSUTF8StringEncoding];
        [fileManager createFileAtPath: filePath contents: data attributes: nil];
        if ([fileManager fileExistsAtPath: filePath]) {
            NSLog(@"a new file was created");
        }
        NSString* destPath = [path stringByAppendingPathComponent: @"testFile_Copy"];
        if ([fileManager copyItemAtPath: filePath toPath: destPath error: nil]) {
            NSLog(@"a new file was copied");
        }
    }
}

@end
